package com.augurit.common.calendar.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.calendar.web.form.SysCalSharedForm;
import com.augurit.common.entity.SysCalShared;
import com.augurit.common.util.lang.DateUtils;

public class SysCalSharedConvertor {
	public static SysCalSharedForm convertVoToForm(SysCalShared entity) {
		if(entity != null) {
			SysCalSharedForm form = new SysCalSharedForm();
			form.setId(entity.getId());
			form.setEventId(entity.getEventId());
			form.setShareUserId(entity.getShareUserId());
			form.setShareType(entity.getShareType());
			form.setShareTypeName(entity.getShareType().equals(SysCalSharedForm.READ_SHARE_TYPE)?"只读":"读写");
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(SysCalSharedForm form, SysCalShared entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			entity.setEventId(form.getEventId());
			entity.setShareUserId(form.getShareUserId());
			entity.setShareType(form.getShareType());
		}
	}
	
	public static List<SysCalSharedForm> convertVoListToFormList(List<SysCalShared> sysCalSharedList) {
		if(sysCalSharedList != null && sysCalSharedList.size() > 0) {
			List<SysCalSharedForm> sysCalSharedFormList = new ArrayList();
			for(int i=0; i<sysCalSharedList.size(); i++) {
				sysCalSharedFormList.add(convertVoToForm(sysCalSharedList.get(i)));
			}
			return sysCalSharedFormList;
		}
		return null;
	}
	
	public static List<SysCalSharedForm> covertObjsToFormList(List<Object[]> objs){
		List<SysCalSharedForm> result = null;
		if(objs != null && objs.size() > 0){
			result = new ArrayList<SysCalSharedForm>();
			for(Object[] obj:objs){
				SysCalShared entity = (SysCalShared)obj[0];
				String userName = (String)obj[1];
				
				SysCalSharedForm form = convertVoToForm(entity);
				form.setShareUserName(userName);
				result.add(form);
			}
		}
		return result;
	}
	
	public static List<Map> convertVoListToMapList(List<SysCalShared> sysCalSharedList) {
		if(sysCalSharedList != null && sysCalSharedList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<sysCalSharedList.size(); i++) {
				SysCalShared entity = sysCalSharedList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("eventId", entity.getEventId() == null ? "" : entity.getEventId().toString());
				map.put("shareUserId", entity.getShareUserId() == null ? "" : entity.getShareUserId().toString());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<SysCalShared> convertFormListToVoList(List<SysCalSharedForm> sysCalSharedFormList) {
		if(sysCalSharedFormList != null && sysCalSharedFormList.size() > 0) {
			List<SysCalShared> sysCalSharedList = new ArrayList();
			for(int i=0; i<sysCalSharedFormList.size(); i++) {
				SysCalShared sysCalShared = new SysCalShared();
				convertFormToVo(sysCalSharedFormList.get(i), sysCalShared);
				sysCalSharedList.add(sysCalShared);
			}
			return sysCalSharedList;
		}
		return null;
	}
}